package com.demo.recycleviewitemdecorationdemo;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;


/**
 * 作者:zwk
 * 联系方式：497981239@qq.com
 * 时间：on 2019/7/10 12:06
 * 功能：
 */
public class LinearItemDecoration extends RecyclerView.ItemDecoration {

	private int space;

	public LinearItemDecoration(int space) {
		this.space = space;
	}

	@Override
	public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {


		outRect.left = space;
		outRect.right = space;
		outRect.bottom = space;
		Log.d("zwk", "-----设置后left-----" + outRect.left);
		Log.d("zwk", "-----设置后right-----" + outRect.right);
		Log.d("zwk", "-----设置后bottom-----" + outRect.bottom);

		// Add top margin only for the first item to avoid double space between items
		if (parent.getChildPosition(view) == 0)
			outRect.top = space;

		Log.d("zwk", "-----设置后top-----" + outRect.top);

	}


	@Override
	public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
		super.onDraw(c, parent, state);
		int left = parent.getPaddingLeft();
		Log.d("zwk", "-----left" + left);
		int right = parent.getPaddingRight();
		Log.d("zwk", "-----right" + right);
		int top = parent.getPaddingTop();
		Log.d("zwk", "-----top" + top);
		int bottom = parent.getPaddingBottom();
		Log.d("zwk", "-----bottom" + bottom);

	}

	@Override
	public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
		super.onDrawOver(c, parent, state);
	}
}
